﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Staff_AdminChangePassword : AdminBasePage
{
    public int staffid;
    BLLStaffManagement bllStaff = new BLLStaffManagement();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (LoginedStaff.tblRole.Role != "Admin")
            Response.Redirect("~/Admin/Index.aspx");

        tblStaff staff = null;
        if (!IsPostBack)
        {
            if (Request.QueryString["staffid"] != null)
            {
                try
                {
                    staffid = Convert.ToInt16(Request.QueryString["staffid"]);
                    staff = bllStaff.GetStaff(staffid);
                }
                catch
                {
                    staffid = 0;
                }
            }
            else if (isLogin())
            {
                staff = LoginedStaff;
            }
            else
            {
                Response.Redirect("~/Admin/Stafflogin.aspx");
            }

            if (staff != null)
            {
                tbName.Text = staff.Username;
                hiddStaffID.Value = staff.ID.ToString();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        tblStaff staff = null;
        Hash cipher = new Hash();
        if (Request.QueryString["staffid"] != null)
        {
            try
            {
                staffid = Convert.ToInt16(Request.QueryString["staffid"]);
                staff = bllStaff.GetStaff(staffid);
            }
            catch
            {
                staffid = 0;
            }
        }
        else if (isLogin())
        {
            staff = LoginedStaff;

        }
        staff.Password = cipher.hash(tbPass.Text);
        bllStaff.UpdateStaff(staff);
        Response.Redirect("~/Admin/Staff/ListStaff.aspx");
    }
}
